<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>学员管理系统</title>
    <meta name="keywords" content="学员管理系统" />
    <meta name="description" content="学员管理系统 " />
    <meta name="author" content="js代码" />
    <meta name="copyright" content="js代码" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="./css/x-admin.css" media="all">
    <link rel="stylesheet" href="./lib/layui-v2.5.5/css/layui.css">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>问题/资讯列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">

    <button class="layui-btn" id="add"><i class="layui-icon">&#xe608;</i>添加</button>
    <button class="layui-btn" onclick="question_add('添加班级','class-addall.jsp','600','200')"><i class="layui-icon">&#xe608;</i>导入excel添加</button></xblock>

    <table class="layui-hide" id="current" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="toolbar1"></script>
    <script type="text/html" id="toolBar2" lay-filter="test1">
        <a type="submit" id="edit" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">
<%--           onclick="question_edit('编辑','/adminsedit?aid={{d.aid}}','600','500')">--%>
            <i class="layui-icon">&#xe642;</i>
        </a>
    </script>
    <form id="test" class="layui-form" lay-fiter="example" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">班级名称</label>
            <div class="layui-input-block">
                <input id="cname" type="text" name="cname" lay-verify="title" autocomplete="off" placeholder="请输入班级名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="submit" class="layui-btn"
                lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="./lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="./js/x-layui.js" charset="utf-8"></script>
<script src="./js/common.js" charset="utf-8"></script>
<script>
    layui.use(['table','jquery','layer'],function (){
        $=layui.jquery,
            layer=layui.layer,
            table=layui.table
        var tables=table.render({
            elem: '#current',
            url: '/classesShow',
            toolbar:'#toolbar1',
            cols: [[
                {field: 'cid', title: '编号', sort: true, width: 100},
                {field: 'cname', title: '班级名称', width: 120},
                {title: '操作', toolbar: '#toolBar2', width: 120, align: 'center'}
            ]],
            limits: [5, 10, 20, 50, 100],
            limit: 5,//每页显示几行数据
            page: true,//允许分页
            parseData: function (res) {
                return{
                    "code":0,
                    "count":res.count,
                    "data":res.data
                };
            },
            done: function (res, curr, count) {

            }
        });
        //修改
        table.on('tool(currentTableFilter)',function (obj) {
            let data1=obj.data;
            if(obj.event=='edit'){
                layer.open({
                    title:'添加班级',
                    type:1,
                    skin:'layui-layer-rim',//加上边框
                    area:['400px','200px'],//宽高
                    content:$('#test'),
                });
                $('#cname').val(data1.cname);
                $('#submit').click(function (){
                    let cname1= $('#cname').val();
                    let cid=data1.cid;
                    var res1=post('/classesadd',{cid:cid,cname:cname1});
                    if(res1.code==0){
                        let index=layer.alert('提交成功！',function (){
                            layer.close(index);
                            tables.reload({
                                where:{'cname':'aa'},
                                page:{curr:1}
                            });
                        });
                    }else layer.alert('失败',{icon:5});
                    return false;
                });
            }
        })
        //添加
        $('#add').click(function (){
            layer.open({
                title:'添加班级',
                type:1,
                skin:'layui-layer-rim',//加上边框
                area:['400px','200px'],//宽高
                content:$('#test'),
            });
            $('#cname').val('');
            $('#submit').click(function (){
                let cname=$('#cname').val();
                let res=post('/classesadd', {cname:cname});
                if(res.code==0){
                    layer.alter('操作成功！',{icon:6},function (){
                        var index=parent.layer.getFrameIndex(window.name);
                        //关闭当前的frame
                        parent.layer.close(index);
                    });
                }else  layer.alter('失败',{icon:5});
                return false;
            });
        });


    });


    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
        });
    }

    function question_show (argument) {
        layer.msg('可以跳到前台具体问题页面',{icon:1,time:1000});
    }
    /*添加*/
    function question_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    //编辑
    function question_edit (title,url,id,w,h) {
        x_admin_show(title,url,w,h);
    }

    /*删除*/
    function question_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }
</script>
</body>
</html>
